/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.structure;

import com.zsmartsystems.zigbee.IeeeAddress;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberKeyData;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspDeserializer;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspSerializer;

/**
 * Class to implement the Ember Structure <b>EmberTransientKeyData</b>.
 * <p>
 * The transient key data structure.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class EmberTransientKeyData {

    /**
     * The IEEE address paired with the transient link key.
     * <p>
     * EZSP type is <i>EmberEUI64</i> - Java type is {@link IeeeAddress}
     */
    private IeeeAddress eui64;

    /**
     * The key data structure matching the transient key.
     * <p>
     * EZSP type is <i>EmberKeyData</i> - Java type is {@link EmberKeyData}
     */
    private EmberKeyData keyData;

    /**
     * The incoming frame counter associated with this key.
     * <p>
     * EZSP type is <i>uint32_t</i> - Java type is {@link int}
     */
    private int incomingFrameCounter;

    /**
     * The number of milliseconds remaining before the key is automatically timed out of the
     * transient key table.
     * <p>
     * EZSP type is <i>uint32_t</i> - Java type is {@link int}
     */
    private int countdownTimerMs;

    /**
     * Default Constructor
     */
    public EmberTransientKeyData() {
    }

    public EmberTransientKeyData(EzspDeserializer deserializer) {
        deserialize(deserializer);
    }

    /**
     * The IEEE address paired with the transient link key.
     * <p>
     * EZSP type is <i>EmberEUI64</i> - Java type is {@link IeeeAddress}
     *
     * @return the current eui64 as {@link IeeeAddress}
     */
    public IeeeAddress getEui64() {
        return eui64;
    }

    /**
     * The IEEE address paired with the transient link key.
     *
     * @param eui64 the eui64 to set as {@link IeeeAddress}
     */
    public void setEui64(IeeeAddress eui64) {
        this.eui64 = eui64;
    }

    /**
     * The key data structure matching the transient key.
     * <p>
     * EZSP type is <i>EmberKeyData</i> - Java type is {@link EmberKeyData}
     *
     * @return the current keyData as {@link EmberKeyData}
     */
    public EmberKeyData getKeyData() {
        return keyData;
    }

    /**
     * The key data structure matching the transient key.
     *
     * @param keyData the keyData to set as {@link EmberKeyData}
     */
    public void setKeyData(EmberKeyData keyData) {
        this.keyData = keyData;
    }

    /**
     * The incoming frame counter associated with this key.
     * <p>
     * EZSP type is <i>uint32_t</i> - Java type is {@link int}
     *
     * @return the current incomingFrameCounter as {@link int}
     */
    public int getIncomingFrameCounter() {
        return incomingFrameCounter;
    }

    /**
     * The incoming frame counter associated with this key.
     *
     * @param incomingFrameCounter the incomingFrameCounter to set as {@link int}
     */
    public void setIncomingFrameCounter(int incomingFrameCounter) {
        this.incomingFrameCounter = incomingFrameCounter;
    }

    /**
     * The number of milliseconds remaining before the key is automatically timed out of the
     * transient key table.
     * <p>
     * EZSP type is <i>uint32_t</i> - Java type is {@link int}
     *
     * @return the current countdownTimerMs as {@link int}
     */
    public int getCountdownTimerMs() {
        return countdownTimerMs;
    }

    /**
     * The number of milliseconds remaining before the key is automatically timed out of the
     * transient key table.
     *
     * @param countdownTimerMs the countdownTimerMs to set as {@link int}
     */
    public void setCountdownTimerMs(int countdownTimerMs) {
        this.countdownTimerMs = countdownTimerMs;
    }

    /**
     * Serialise the contents of the EZSP structure.
     *
     * @param serializer the {@link EzspSerializer} used to serialize
     */
    public int[] serialize(EzspSerializer serializer) {
        // Serialize the fields
        serializer.serializeEmberEui64(eui64);
        serializer.serializeEmberKeyData(keyData);
        serializer.serializeUInt32(incomingFrameCounter);
        serializer.serializeUInt32(countdownTimerMs);
        return serializer.getPayload();
    }

    /**
     * Deserialise the contents of the EZSP structure.
     *
     * @param deserializer the {@link EzspDeserializer} used to deserialize
     */
    public void deserialize(EzspDeserializer deserializer) {
        // Deserialize the fields
        eui64 = deserializer.deserializeEmberEui64();
        keyData = deserializer.deserializeEmberKeyData();
        incomingFrameCounter = deserializer.deserializeUInt32();
        countdownTimerMs = deserializer.deserializeUInt32();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(124);
        builder.append("EmberTransientKeyData [eui64=");
        builder.append(eui64);
        builder.append(", keyData=");
        builder.append(keyData);
        builder.append(", incomingFrameCounter=");
        builder.append(incomingFrameCounter);
        builder.append(", countdownTimerMs=");
        builder.append(countdownTimerMs);
        builder.append(']');
        return builder.toString();
    }
}
